import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker_plus/flutter_datetime_picker_plus.dart';
import "package:get/get.dart";

class PublishTask extends StatelessWidget {
  final RxInt _selectedValue = 0.obs;

  //  @override
  // void initState() {
  //  // super.initState();
  //   // 这里可以设置默认值，例如：
  //   // _selectedDate = DateTime.parse("2023-01-01 12:00:00"); // 举例设置为2023年1月1日12点

  // }

  @override
  Widget build(BuildContext context) {
    //  print(DateTime.parse("2023-01-01 12:00:00"));

    return Scaffold(
        appBar: AppBar(
          backgroundColor: Color(0xffffffff),
          centerTitle: true,
          leadingWidth: 40,
          title: Text('发布任务', style: TextStyle(fontSize: 16)),
          leading: IconButton(
            onPressed: () {
              Get.back();
              print('object');
            },
            icon: Image.asset('static/images/back.png'),
          ),
        ),
        body: Padding(
          padding: EdgeInsets.symmetric(horizontal: 15),
          child: Column(
            children: [
              Expanded(
                  child: ListView(
                children: [
                  Text(
                    '任务标题',
                    style: TextStyle(fontSize: 14),
                  ),
                  InputFieldWithCounter(),
                  SizedBox(
                    height: 25,
                  ),
                  Text(
                    '任务图片',
                    style: TextStyle(fontSize: 14),
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  Wrap(
                    children: [
                      Stack(
                        children: [
                          ClipRRect(
                            borderRadius: BorderRadius.circular(10), // 设置圆角半径
                            // child: Image.asset(
                            //   width: 80,
                            //   height: 80,
                            //   'static/aaa.png',
                            //   fit: BoxFit.fill,
                            // ),
                          ),
                          Positioned(
                            top: 5.0,
                            right: 5,
                            child: ClipRRect(
                              borderRadius: BorderRadius.circular(20), // 设置圆角半径
                              child: Image.asset(
                                width: 20,
                                height: 20,
                                'static/guanbi.png',
                                fit: BoxFit.fill,
                              ),
                            ),
                          )
                        ],
                      ),
                      Container(
                        width: 80,
                        height: 80,
                        margin: EdgeInsets.only(left: 10),
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(10),
                            color: Color(0xfff5f5f5)),
                        child: IconButton(
                          iconSize: 30,
                          icon: Icon(Icons.add),
                          color: Color(0xff999999),
                          onPressed: () {
                            // 点击事件处理
                            print('加号被点击');
                          },
                        ),
                      )
                    ],
                  ),
                  SizedBox(
                    height: 30,
                  ),
                  Text(
                    '内容要求',
                    style: TextStyle(fontSize: 14),
                  ),
                  Container(
                      margin: EdgeInsets.only(top: 10),
                      decoration: BoxDecoration(
                          border: Border(
                              bottom: BorderSide(color: Color(0xffdddddd)))),
                      child: Row(
                        children: [
                          Expanded(
                            child: TextField(
                              minLines: 3,
                              maxLines: null,
                              decoration: InputDecoration(
                                hintStyle: TextStyle(
                                    color: Color(0xff999999), fontSize: 12),
                                border: InputBorder.none, // 移除边框
                                hintText: '请输入参与任务发布的内容要求',
                              ),
                            ),
                          ),
                          // SizedBox(width: 8),
                          // Text(
                          //   '1/21',
                          //   style: TextStyle(color: Colors.grey),
                          // ),
                        ],
                      )),
                  SizedBox(
                    height: 20,
                  ),
                  Text(
                    '达成条件',
                    style: TextStyle(fontSize: 14),
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Radio<int>(
                        value: 1,
                        groupValue: _selectedValue.value,
                        onChanged: (value) {
                          print('object');
                          _selectedValue.value = value!;
                        },
                      ),
                      Text(
                        '点赞数大于等于',
                        style: TextStyle(fontSize: 14),
                      ),
                      Container(
                        decoration: BoxDecoration(
                            border: Border(
                                bottom: BorderSide(color: Color(0xffdddddd)))),
                        width: 100,
                        child: TextField(
                          style: TextStyle(fontSize: 18),
                          decoration: InputDecoration(
                            isCollapsed: true, //设置高度
                            contentPadding: EdgeInsets.all(12),
                            hintStyle: TextStyle(color: Color(0xff999999)),
                            border: InputBorder.none, // 隐藏输入框默认边框
                            hintText: '0', // 提示文本
                          ),
                        ),
                      )
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Radio<int>(
                        value: 1,
                        groupValue: _selectedValue.value,
                        onChanged: (value) {
                          print('object');
                          _selectedValue.value = value!;
                        },
                      ),
                      Text(
                        '评论数大于等于',
                        style: TextStyle(fontSize: 14),
                      ),
                      Container(
                        decoration: BoxDecoration(
                            border: Border(
                                bottom: BorderSide(color: Color(0xffdddddd)))),
                        width: 100,
                        child: TextField(
                          style: TextStyle(fontSize: 18),
                          decoration: InputDecoration(
                            isCollapsed: true, //设置高度
                            contentPadding: EdgeInsets.all(12),
                            hintStyle: TextStyle(color: Color(0xff999999)),
                            border: InputBorder.none, // 隐藏输入框默认边框
                            hintText: '0', // 提示文本
                          ),
                        ),
                      )
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Radio<int>(
                        value: 1,
                        groupValue: _selectedValue.value,
                        onChanged: (value) {
                          print('object');
                          _selectedValue.value = value!;
                        },
                      ),
                      Text(
                        '转发数大于等于',
                        style: TextStyle(fontSize: 14),
                      ),
                      Container(
                        decoration: BoxDecoration(
                            border: Border(
                                bottom: BorderSide(color: Color(0xffdddddd)))),
                        width: 100,
                        child: TextField(
                          style: TextStyle(fontSize: 18),
                          decoration: InputDecoration(
                            isCollapsed: true, //设置高度
                            contentPadding: EdgeInsets.all(12),
                            hintStyle: TextStyle(color: Color(0xff999999)),
                            border: InputBorder.none, // 隐藏输入框默认边框
                            hintText: '0', // 提示文本
                          ),
                        ),
                      )
                    ],
                  ),
                  GestureDetector(
                    onTap: () => {
                      DatePicker.showDateTimePicker(context,
                          showTitleActions: true,
                          minTime: DateTime(2000, 1, 1),
                          maxTime: DateTime(2100, 12, 31), onChanged: (date) {
                        print('onChange: $date');
                      }, onConfirm: (date) {
                        print('onConfirm: $date');
                      }, currentTime: DateTime.now(), locale: LocaleType.zh)
                    },
                    child: Container(
                      margin: EdgeInsets.only(top: 20),
                      padding: EdgeInsets.symmetric(vertical: 15),
                      decoration: BoxDecoration(
                          border: Border(
                              bottom: BorderSide(color: Color(0xffdddddd)))),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [Text('结束时间'), Text('')],
                      ),
                    ),
                  ),
                  GestureDetector(
                    onTap: () => {
                      DatePicker.showDateTimePicker(context,
                          showTitleActions: true,
                          minTime: DateTime(2000, 1, 1),
                          maxTime: DateTime(2100, 12, 31), onChanged: (date) {
                        print('onChange: $date');
                      }, onConfirm: (date) {
                        print('onConfirm: $date');
                      }, currentTime: DateTime.now(), locale: LocaleType.zh)
                    },
                    child: Container(
                      padding: EdgeInsets.symmetric(vertical: 15),
                      decoration: BoxDecoration(
                          border: Border(
                              bottom: BorderSide(color: Color(0xffdddddd)))),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [Text('开始时间'), Text('')],
                      ),
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(vertical: 15),
                    decoration: BoxDecoration(
                        border: Border(
                            bottom: BorderSide(color: Color(0xffdddddd)))),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('任务数量'),
                        Expanded(
                          child: TextField(
                            textAlign: TextAlign.right,
                            style: TextStyle(
                              fontSize: 12,
                            ),
                            decoration: InputDecoration(
                              isCollapsed: true, //设置高度
                              hintStyle: TextStyle(color: Color(0xff999999)),
                              border: InputBorder.none, // 隐藏输入框默认边框
                              hintText: '填写话题简介', // 提示文本
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  SizedBox(
                    height: 15,
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [Text('奖励'), Text('0.00 ST')],
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  Text(
                    '发布须知',
                    style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
                  ),
                  SizedBox(
                    height: 5,
                  ),
                  Text('1、发布任务需要缴纳足够的星币；'),
                  // SizedBox(
                  //   height: 2,
                  // ),
                  // Text('1、发布任务需要缴纳足够的星币；'),
                ],
              )),
              Container(
                margin: EdgeInsets.symmetric(vertical: 15),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          children: [
                            Text(
                              '33',
                              style: TextStyle(
                                  fontSize: 20, color: Color(0XFFEF0000)),
                            ),
                            Text(
                              'ST',
                              style: TextStyle(
                                  fontSize: 12, color: Color(0XFF999999)),
                            ),
                            SizedBox(
                              width: 23,
                            ),
                            Container(
                                padding: EdgeInsets.symmetric(
                                    vertical: 1, horizontal: 5),
                                decoration: BoxDecoration(
                                  color: Color(0XFFF5F5F5),
                                ),
                                child: GestureDetector(
                                  onTap: () {
                                    Get.bottomSheet(
                                        Padding(
                                          padding: EdgeInsets.symmetric(
                                              horizontal: 15, vertical: 15),
                                          child: Column(
                                            children: [
                                              Row(
                                                mainAxisAlignment:
                                                    MainAxisAlignment
                                                        .spaceBetween,
                                                children: [
                                                  SizedBox(
                                                    width: 55,
                                                  ),
                                                  Expanded(
                                                      child: Align(
                                                    child: Text(
                                                      '金额明细',
                                                      style: TextStyle(
                                                          fontSize: 16),
                                                    ),
                                                  )),
                                                  TextButton(
                                                    onPressed: () {
                                                      Get.back(); // 调用关闭弹窗
                                                      // 可在此处执行关闭后的回调逻辑
                                                    },
                                                    child: Image.asset(
                                                      'static/close.png',
                                                      width: 16,
                                                      fit: BoxFit.fitWidth,
                                                    ),
                                                  ),
                                                ],
                                              ),
                                              SizedBox(
                                                height: 15,
                                              ),
                                              Row(
                                                mainAxisAlignment:
                                                    MainAxisAlignment
                                                        .spaceBetween,
                                                children: [
                                                  Text(
                                                    '任务金额',
                                                    style: TextStyle(
                                                        color:
                                                            Color(0XFF999999)),
                                                  ),
                                                  Row(
                                                    children: [
                                                      Text(
                                                        '233 ',
                                                        style: TextStyle(
                                                            color: Color(
                                                                0XFFEF0000),
                                                            fontSize: 14),
                                                      ),
                                                      Text(
                                                        ' ST',
                                                        style: TextStyle(
                                                            fontSize: 12),
                                                      ),
                                                    ],
                                                  ),
                                                ],
                                              ),
                                              SizedBox(
                                                height: 10,
                                              ),
                                              Row(
                                                mainAxisAlignment:
                                                    MainAxisAlignment
                                                        .spaceBetween,
                                                children: [
                                                  Text(
                                                    '平台服务费',
                                                    style: TextStyle(
                                                        color:
                                                            Color(0XFF999999)),
                                                  ),
                                                  Row(
                                                    children: [
                                                      Text(
                                                        '233 ',
                                                        style: TextStyle(
                                                            color: Color(
                                                                0XFFEF0000),
                                                            fontSize: 14),
                                                      ),
                                                      Text(
                                                        ' ST',
                                                        style: TextStyle(
                                                            fontSize: 12),
                                                      ),
                                                    ],
                                                  ),
                                                ],
                                              ),
                                              SizedBox(
                                                height: 10,
                                              ),
                                              Align(
                                                alignment:
                                                    Alignment.centerRight,
                                                child: Text('您的ST余额为23023.22',
                                                    style: TextStyle(
                                                        fontSize: 12,
                                                        color:
                                                            Color(0XFF999999))),
                                              ),
                                              Expanded(child: SizedBox()),
                                              Container(
                                                margin: EdgeInsets.symmetric(
                                                    vertical: 15),
                                                child: Row(
                                                  mainAxisAlignment:
                                                      MainAxisAlignment
                                                          .spaceBetween,
                                                  children: [
                                                    Column(
                                                      crossAxisAlignment:
                                                          CrossAxisAlignment
                                                              .start,
                                                      children: [
                                                        Row(
                                                          children: [
                                                            Text(
                                                              '33',
                                                              style: TextStyle(
                                                                  fontSize: 20,
                                                                  color: Color(
                                                                      0XFFEF0000)),
                                                            ),
                                                            Text(
                                                              'ST',
                                                              style: TextStyle(
                                                                  fontSize: 12,
                                                                  color: Color(
                                                                      0XFF999999)),
                                                            ),
                                                            SizedBox(
                                                              width: 23,
                                                            ),
                                                          ],
                                                        ),
                                                        Text(
                                                          '含1%的平台服务费',
                                                          style: TextStyle(
                                                              fontSize: 12,
                                                              color: Color(
                                                                  0XFF999999)),
                                                        ),
                                                      ],
                                                    ),
                                                    Container(
                                                        alignment:
                                                            Alignment.center,
                                                        width: 200,
                                                        height: 50,
                                                        decoration:
                                                            BoxDecoration(
                                                          borderRadius:
                                                              BorderRadius
                                                                  .circular(
                                                                      (50)),
                                                          gradient:
                                                              LinearGradient(
                                                            colors: [
                                                              Color(0xff2189E7),
                                                              Color(0xffBF67F8),
                                                            ], // 定义颜色列表
                                                            begin: Alignment
                                                                .topLeft, // 渐变开始的位置
                                                            end: Alignment
                                                                .bottomRight, // 渐变结束的位置
                                                          ),
                                                        ),
                                                        child: GestureDetector(
                                                          onTap: () => {
                                                            Get.toNamed(
                                                                '/talk/submit_task')
                                                          },
                                                          child: Text(
                                                            '发布任务',
                                                            style: TextStyle(
                                                                color: Color(
                                                                    0XFFFFFFFF),
                                                                fontSize: 16),
                                                          ),
                                                        ))
                                                  ],
                                                ),
                                              )
                                            ],
                                          ),
                                        ),
                                        shape: RoundedRectangleBorder(
                                          // 圆角设置:ml-citation{ref="7" data="citationList"}
                                          borderRadius: BorderRadius.vertical(
                                              top: Radius.circular(10)),
                                        ),
                                        backgroundColor: Colors.white);
                                  },
                                  child: Text(
                                    '明细',
                                    style: TextStyle(fontSize: 11),
                                  ),
                                ))
                          ],
                        ),
                        Text(
                          '含1%的平台服务费',
                          style:
                              TextStyle(fontSize: 12, color: Color(0XFF999999)),
                        ),
                      ],
                    ),

                    GestureDetector(
                      onTap: (){
                         Get.dialog(
                              AlertDialog(
                                backgroundColor: Colors.transparent,
                                content: Stack(
                                  children: [
                                    ClipRRect(
                                      borderRadius: BorderRadius.circular(15.0),
                                      child: Image.asset(
                                        'static/qidai.png',
                                        width: 250,
                                        fit: BoxFit.fitWidth,
                                      ),
                                    ),
                                  ],
                                ),
                              ),
                            );
                            return;
                            // Get.dialog(
                            //   AlertDialog(

                            //     backgroundColor:Color(0XFFFFFFFF),
                            //     shape: RoundedRectangleBorder(
                            //         borderRadius: BorderRadius.circular(10)),
                            //     content:Container(
                            //       height: 220,
                            //       child: Column(
                            //       children: [
                            //         Image.asset('static/images/tongguo.png',width: 80,fit:BoxFit.fitWidth,),
                            //         SizedBox(height: 10,),
                            //         Text('恭喜您',style: TextStyle(fontSize: 16),),
                            //         SizedBox(height: 10,),
                            //         Text('任务发布成功',style: TextStyle(fontSize: 12),),
                            //         Expanded(child:
                            //         SizedBox(),
                            //         ),
                            //         Container(
                            //           height: 35,
                            //           alignment: Alignment.center,
                            //            decoration: BoxDecoration(
                            //             borderRadius: BorderRadius.circular((35)),
                            //             gradient: LinearGradient(
                            //             colors: [
                            //             Color(0xff2189E7),
                            //             Color(0xffBF67F8),
                            //             ], // 定义颜色列表
                            //             begin: Alignment.topLeft, // 渐变开始的位置
                            //             end: Alignment.bottomRight, // 渐变结束的位置
                            //             ),
                            //             ),
                            //             child: Text('确认',style: TextStyle(fontSize: 12,color: Color(0XFFFFFFFF)),),
                            //         )
                            //       ],
                            //     ) ,
                            //     )
                            //     ,
                            //   ),
                            // )
                      },
                      child:  Container(
                        alignment: Alignment.center,
                        width: 200,
                        height: 50,
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular((50)),
                          gradient: LinearGradient(
                            colors: [
                              Color(0xff2189E7),
                              Color(0xffBF67F8),
                            ], // 定义颜色列表
                            begin: Alignment.topLeft, // 渐变开始的位置
                            end: Alignment.bottomRight, // 渐变结束的位置
                          ),
                        ),
                        child: Text(
                            '发布任务',
                            style: TextStyle(
                                color: Color(0XFFFFFFFF), fontSize: 16),
                          )),
                    )
                   
                  ],
                ),
              )
            ],
          ),
        ));
  }
}

class InputFieldWithCounter extends StatefulWidget {
  @override
  _InputFieldWithCounterState createState() => _InputFieldWithCounterState();
}

class _InputFieldWithCounterState extends State<InputFieldWithCounter> {
  final int maxCount = 20; // 最大计数器值
  int currentCount = 0; // 当前计数器值（虽然在这个示例中不会改变）
  TextEditingController _controller = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Container(
        margin: EdgeInsets.only(top: 10),
        decoration: BoxDecoration(
            border: Border(bottom: BorderSide(color: Color(0xffdddddd)))),
        child: Row(
          children: [
            Expanded(
              child: TextField(
                controller: _controller,
                decoration: InputDecoration(
                  hintStyle: TextStyle(color: Color(0xff999999), fontSize: 12),
                  border: InputBorder.none, // 移除边框
                  hintText: '请输入任务标题',
                ),
              ),
            ),
            SizedBox(width: 8),
            Text(
              '${currentCount}/${maxCount}',
              style: TextStyle(color: Colors.grey),
            ),
          ],
        ));
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
}
